# Model Fields

# Note: Optional arguments are using defaults that match what Django will use
# as a default, e.g. with max_length fields.  Doing this as a form of self
# documentation and to make it easy to know whether you should override the
# default or not.

# Note: Optional arguments that are booleans will use the opposite since you
# can either not specify them, or override them, e.g. auto_now_add=False.

snippet bool
	${1:FIELDNAME} = Bool(${2:default=${3:True}})
snippet date
	${1:FIELDNAME} = Date(${2:default=datetime.now()})
snippet datetime
	${1:FIELDNAME} = DateTime(${2:default=datetime.now()})
snippet decimal
	${1:FIELDNAME} = Decimal(${2:default=u''})
snippet float
	${1:FIELDNAME} = Float(${2:default=0})
snippet int
	${1:FIELDNAME} = Int(default=${2:0})
snippet id
	${1:id} = Int(primary=True)
snippet list
	${1:FIELDNAME} = List()
snippet pickle
	${1:FIELDNAME} = Pickle()
snippet reference
	from ${1:model} import ${2:Model}
	${3:FIELDNAME} = Reference(${4:from_id}, ${5:Model.id})
snippet rawstr
	${1:FIELDNAME} = RawStr()
snippet time
	${1:FIELDNAME} = Time()
snippet timedelta
	${1:FIELDNAME} = TimeDelta()
snippet url
	${1:FIELDNAME} = Unicode(${2:default=u''})

# Code Skeletons

snippet model
	# ${1:comment}
	class ${2:ModelName}(models.Model):
		"""${3:docstring}"""
		${4}
		
		@classmethod
		def ${5:method_name}(cls${6:, args}):
			${7}

snippet autoreload
	${1:obj}.id = AutoReload
snippet store(find)
	${1:obj} = store.find(${2:ModelName}, ${3:ModelName.id}==${4:int(id)}).one()
snippet store(find-list)
	${1:object_list} = store.find(${2:ModelName}).order_by(Asc('id'))
snippet store(remove)
	${1:object_list} = store.find(${2:ModelName},*expression).remove()
snippet view
	class ${1:ViewName}(${2:Admin}${3:Ajax}Handler):
		rule = Rule('/${4:url}/')
		def get(self):
			${5}
			tmpl = env.get_template('${6:template_path}')
			return Response(tmpl.render(request=self.request,
					errors=self.errors))
		def post(self):
			${7}
			tmpl = env.get_template('${8:template_path}')
			return Response(encodeJsonMsg(True, tmpl.render(
						request=self.request,
						errors=self.errors,
					)))


snippet response(Response)
	response = Response(${1:tmpl.render(request=self.request, errors=self.errors)})
snippet response(redirect)
	response = redirect('${1:url}')
	
snippet tabularinline
	class ${1:ModelName}Inline(admin.TabularInline):
		model = $1

snippet stackedinline
	class ${1:ModelName}Inline(admin.StackedInline):
		model = $1

snippet r2r
	response = Response()
	return render_to_response('${1:template.html}', {
			${2}
		}${3:, context_instance=RequestContext(request)}
	)
# comment # --------------------------------------------------------------------
snippet #-
	# --------------------------------------------------------------------
# comment # ---------------------------- zhangpeng -----------------------------
snippet #
	# ---------------------------- zhangpeng -----------------------------
# comment ##
snippet ##
	######################################################################
	# ${1}
	######################################################################
